//
//  NCChatViewCustomCell.m
//  Masonry
//
//  Created by LINAICAI on 2018/5/7.
//

#import "NCChatViewCustomCell.h"
#import "NCChatGuideView.h"
@implementation NCChatViewCustomCell

- (void)awakeFromNib {
    [super awakeFromNib];
    ///设置背景视图
    self.bgView.layer.cornerRadius = 8.0;
    self.bgView.layer.masksToBounds = NO;
    ///设置内容
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    self.contentLabel.textAlignment = NSTextAlignmentCenter;
    self.contentLabel.textColor = [UIColor colorWithRed:45/255.0 green:45/255.0 blue:45/255.0 alpha:1.0];
    self.contentLabel.linkAttributes = @{(NSString *)kCTUnderlineStyleAttributeName : [NSNumber numberWithBool:NO],
                                         (NSString*)kCTForegroundColorAttributeName : (id)[[UIColor colorWithRed:67/255.0 green:177/255.0 blue:255/255.0 alpha:1.0] CGColor]};
    [self.contentLabel setDelegate:(id<TTTAttributedLabelDelegate>)self];
    ///设置小蜜图
    self.beeImage.image = NCChatUIImage(@"bee");
    
}
- (void)setMessage:(NCChatCustomMessage *)message{
    if (message.isGuide) {
        ///用户指引
        NSString *addString = @" 点击查看";
        self.contentLabel.text = [message.text stringByAppendingString:addString];
        NSRange range = NSMakeRange(message.text.length, addString.length);
        TTTAttributedLabelLink *link = [[TTTAttributedLabelLink alloc]init];
        [self.contentLabel addLinkToURL:[NSURL URLWithString:@"guide"] withRange:range];

    }
    else{
        ///非用户指引
        self.contentLabel.text = message.text;
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)attributedLabel:(TTTAttributedLabel *)label
   didSelectLinkWithURL:(NSURL *)url{
    if ([url.absoluteString containsString:@"guide"]) {
        ///弹出指引页面
        NCChatGuideView *view = [[NCChatGuideView alloc]initWithFrame:UIScreen.mainScreen.bounds];
        [view showInView:UIApplication.sharedApplication.keyWindow];
       
    }
}

@end
